package com.ruoyi.api.resp;

import lombok.Data;

import java.io.Serializable;

/**
 * 统一响应结构体
 */
@Data
public class ApiResponse<T> implements Serializable {
    private String code;       // 状态码
    private String message;    // 消息描述
    private T data;            // 数据体

    public boolean isSuccess() {
        return "200".equals(code); // 根据实际状态码判断
    }

    public static <T> ApiResponse<T> success(T data) {
        ApiResponse<T> response = new ApiResponse<>();
        response.setCode("200");
        response.setMessage("成功");
        response.setData(data);
        return response;
    }

    public static <T> ApiResponse<T> error(String code, String message) {
        ApiResponse<T> response = new ApiResponse<>();
        response.setCode(code);
        response.setMessage(message);
        return response;
    }
}
